package org.leumasjaffe.initiativeTracker.entity.trap;

import java.util.ArrayList;

import mathematics.probability.UniformRV;

import org.eclipse.jdt.annotation.NonNull;

/**
 * A Trap that represents a hallway of Swinging Blades
 * @author leumasjaffe
 *
 */

public class SwingingBladeTrap extends RandomTrap{
	private int x,y,z,w;
	
	ArrayList<Integer> positions = new ArrayList<Integer>();
	
	/**
	 * Constructs a new SwingingBladeTrap with n blades
	 * @param n The number of blades
	 */
	@SuppressWarnings("null")
	SwingingBladeTrap(int n) {
		super(new UniformRV(1, n));
		for (int i = 1; i <= n; i++)
			this.positions.add(i);
		this.positions = super.<Integer>shuffle(this.positions, this.r[0]);
		this.x = this.positions.remove(0);
		this.y = this.positions.remove(0);
	}


	/**
	 * Prints out the activation of the trap
	 * @param x The first value;
	 * @param y The second value;
	 */
	private void print(int x, int y) {
		System.out.print(getName() + " activates on the lines: ");
		System.out.println("(" + x + ", " + y + ")");
	}


	@SuppressWarnings("null")
	@Override
	public void activate() {
		print(this.x, this.y);
		this.z = this.positions.remove(0);
		this.w = this.positions.remove(0);
		this.positions.add(this.x);
		this.positions.add(this.y);
		this.positions = super.<Integer>shuffle(this.positions, this.r[0]);
		System.out.println();
		System.out.print("Next Turn:\t");
		print(this.z, this.w);
		this.x = this.z;
		this.y = this.w;		
	}

	@Override
	public @NonNull String getName() {
		return "Swinging Blade Trap";
	}

}
